#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>


int main(int argc, char *argv[])
{
        int fd[2];
        char buf1[]="buffer data first\r\n";
        char buf2[]="buffer data second\r\n";
        int len = 0;

        fd[0] = open("a.txt",O_RDWR | O_APPEND,0);
        fd[1] = open("b.txt",O_RDWR | O_APPEND,0);
        dup2(fd[0],fd[1]);
        printf("fd[0]:%d,fd[1]:%d\n",fd[0],fd[1]);

        len = write(fd[0],buf1,strlen(buf1)+1);
        printf("len:%d\n",len);
        if(errno)
        {
                printf("errno:%d\n",errno);
        }

        len = write(fd[1],buf2,sizeof(buf2));
        printf("len:%d\n",len);
        if(errno)
        {
                printf("errno:%d\n",errno);
        }

        close(fd[0]);
        close(fd[1]);

        return 0;
}
                                                